package com.yanftch.hdc_tools.command

import com.yanftch.hdc_tools.common.MessageDelegate
import com.yanftch.hdc_tools.common.executeCommand
import com.yanftch.hdc_tools.common.finalCommandLine
import com.yanftch.hdc_tools.common.isCommandSucceed

class StartAppCommand : Command {
    override fun run(commandContext: CommandContext): Boolean {
        with(commandContext) {
            try {
                val executeCommand = executeCommand(finalCommandLine(hdcPath, hdc_aa_start(bundleName, defaultAbility)))
                if (executeCommand.isCommandSucceed()) {
                    MessageDelegate.info("start app success.", action)
                } else {
                    MessageDelegate.error("start app failed. $executeCommand", action)
                }
            } catch (e: Exception) {
                MessageDelegate.error("StartAppCommand error: ${e.message}", action)
            }
        }
        return false
    }
}